﻿<UserControl x:Class="SlvPartecipazione.CircleBar"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:SlvPartecipazione"
    xmlns:util="clr-namespace:Util"
    mc:Ignorable="d"
    d:DesignHeight="120" d:DesignWidth="120" x:Name="UCCircleBar">

    <UserControl.Resources>

        <Style TargetType="ProgressBar" x:Key="CircularProgressBarStyle">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ProgressBar">
                        <Grid x:Name="LayoutRoot">
                            <!-- attach the view model -->
                            <local:CircularProgressBarViewModel.Attach>
                                <local:CircularProgressBarViewModel HoleSizeFactor="0.84"/>
                            </local:CircularProgressBarViewModel.Attach>

                            <Ellipse Width="{Binding Diameter}" Height="{Binding Diameter}"
                                   HorizontalAlignment="Center" VerticalAlignment="Center"
                                   Stroke="Green" Opacity="0.5" Fill="Transparent"
                                   StrokeThickness="10">
                            </Ellipse>

                            <local:PiePiece CentreX="{Binding CentreX}" CentreY="{Binding CentreY}"
                                          RotationAngle="0" WedgeAngle="{Binding Angle}"
                                          Radius="{Binding Radius}" InnerRadius="{Binding InnerRadius}"
                                          Fill="OrangeRed" Opacity="0.7"/>

                            <Grid util:GridUtils.RowDefinitions="*,2*,*" util:GridUtils.ColumnDefinitions="*,2*,*">
                                <Viewbox Grid.Row="1" Grid.Column="1">
                                    <TextBlock   Text="{Binding ElementName=UCCircleBar, Path=Contatore}" 
                                                 Foreground="White"
                                                 FontWeight="Bold"
                                                 VerticalAlignment="Center" HorizontalAlignment="Center" />
                                </Viewbox>
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <ProgressBar Value="{Binding Value}" 
                 Width="120" Height="120" 
                 Style="{StaticResource CircularProgressBarStyle}" />
    </Grid>
</UserControl>
